<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="./js/vue.js"></script>
    <style>
        .demo1{
            width: 100px;
            height: 100px;
            background-color: aquamarine;
        }

        .div1{
            width: 100px;
            height: 100px;
            background-color: burlywood;
        }
        .div2{
            width: 100px;
            height: 20px;
            background-color: rgb(87, 186, 231);
        }
        .list{
            width: 200px;
            height: 200px;
            background-color: rgb(180, 60, 60);
            overflow: auto;
        }
        li{
            height: 50px;
        }
        *{
            margin-top: 20px;
        }
    </style>
    
</head>
<body>
    <div id="root">
        <h3>欢迎来到{{name}}</h3>
        <!-- 阻止默认事件：这里是点击后不发生跳转 .prevent(事件修饰符)-->
        <a href="http://www.baidu.com" @click.prevent="showInfo">点我提示</a>

        <!-- 阻止冒泡 .stop -->
        <div class="demo1" @click="showInfo">
            <button @click.stop="showInfo">点我提示信息</button>
        </div>

        <!-- 事件只触发一次 .once -->
        <button @click.once="showInfo">点我提示信息</button>

        <!-- 使用事件的捕获模式 .capture 
            捕获：从外到内
            冒泡：从内到外
        -->
        <div class="div1" @click.capture="showMsg('div1')">
            div1
            <div class="div2" @click="showMsg('div2')">
                div2
            </div>
        </div>

        <!-- 只有event.target是当前操作的元素时才触发操作,
            这里的event.target是button，不是div，所以不触发click --- .self 
        -->
        <div class="demo1" @click.self="showInfo">
            <button @click="showInfo">点我提示信息</button>
        </div>

        <!-- 事件的默认行为立即执行，无需等待事件回调执行完毕 .passive -->
        <ul @wheel.passive="demo" class="list">
            <!-- 滚动即触发： 
                 scroll：滚动条的滚动 
                 滚轮滚动： wheel
            -->
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>

        </ul>

    </div>
</body>

<script type="text/javascript">
    Vue.config.productionTip = false; 
    new Vue({ 
      el:'#root', 
      data:{
      name:'尚硅谷'  
      },

      methods: {
          showInfo(e){
              alert('同学你好!')
          },
          showMsg(msg){
              console.log(msg)
          },
          demo(){
              for (let i = 0;i<10000;i++) {
                    console.log('#')
              }
              
          }
      },
    })
    
</script>
</html>